﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Collections;

namespace LCWMS
{
    public partial class w_inv003 : DockContent
    {
        private DataSet dscustomer1;
        private DataSet dscustomer;
        private DataSet dsmove_header;
        private DataSet ds_copy;
        private DataSet ds_temp;
        private DataSet ds_move;
        private string str_sql_where = "";
        private string str_sql = "", str_type = "";
        private string str_warehouse = "";
        private string g_str_loctype = "";
        private int coint = 0;
        DataSet ds_warehouse = new DataSet();
        //返回的商品信息 格式sku
        public static string str_skucode;
        public w_inv003()
        {
            InitializeComponent();
            dvg_move.AutoGenerateColumns = false;
            dvg_move_out.AutoGenerateColumns = false;
            dvg_move_out2.AutoGenerateColumns = false;
        }
        #region
        private void f_disply_detail(string s_consignor, string s_move_no)
        {
            try
            {
                string strsql = "";
                if (str_type == "0")
                {
                    strsql = "select a.move_line_no,a.from_warehouse moveout_warehouse,a.moveout_location,a.sku,b.sku_name,a.move_qty_m,a.move_qty_s,a.stock_qty_m,a.stock_qty_s " +
                            "  ,a.to_warehouse movein_warehouse,a.movein_location,a.move_cubage,a.move_gross_weight,a.move_net_weight,a.cubage,a.gross_weight,a.net_weight,a.inv_org,a.consignor,a.move_no,a.convert_modulus,a.pack_code,b.mix_lotno,b.mix_sku,b.pallet_flag " +
                             " from " + main.g_space + ".inv_move_detail a," + main.g_space + ".mst_sku b where a.inv_org=b.inv_org and a.consignor =b.consignor and a.sku=b.sku" +
                             " and a.inv_org='" + main.g_org + "' and a.consignor='" + s_consignor + "' and a.move_no='" + s_move_no + "' order by a.move_line_no";

                    if (main.dbtype == "SQL")
                    {
                        ds_temp = main.dbservice.Sql_exec_selectsql(strsql);
                    }
                    else
                    {
                        ds_temp = main.dbservice.oracle_exec_selectsql(strsql);
                    }
                    this.dvg_move_out.DataSource = ds_temp.Tables[0];
                    ds_copy = ds_temp.Copy();
                }
                else
                {
                    strsql = "select a.move_line_no,a.moveout_pallet,a.batchno,a.movein_pallet,a.from_warehouse moveout_warehouse,a.moveout_location,a.sku,b.sku_name,a.move_qty_m,a.move_qty_s," +
                               " a.move_qty_m stock_qty_m,a.move_qty_s stock_qty_s   ,a.to_warehouse movein_warehouse,a.movein_location,a.move_cubage,a.move_gross_weight," +
                               " a.move_net_weight,a.cubage,a.gross_weight,a.net_weight,a.inv_org,a.consignor,a.move_no,a.convert_modulus,a.pack_code," +
                               " b.mix_lotno,b.mix_sku,b.pallet_flag ,a.lot_attribute1,	a.lot_attribute2,	a.lot_attribute3,	a.lot_attribute4," +
                               " a.lot_attribute5,	a.lot_attribute6,	a.lot_attribute7,	a.lot_attribute8,	a.lot_attribute9,	a.lot_attribute10," +
                               " a.lot_attribute11,	a.lot_attribute12,	a.lot_attribute13,	a.lot_attribute14,	a.lot_attribute15 " +
                               " from " + main.g_space + ".inv_move_detail a," + main.g_space + ".mst_sku b " +
                               " where a.inv_org=b.inv_org and a.consignor =b.consignor and a.sku=b.sku   " +
                               " and a.inv_org='" + main.g_org + "' and a.consignor='" + s_consignor + "' and a.move_no='" + s_move_no + "'";

                    if (main.dbtype == "SQL")
                    {
                        ds_temp = main.dbservice.Sql_exec_selectsql(strsql);
                    }
                    else
                    {
                        ds_temp = main.dbservice.oracle_exec_selectsql(strsql);
                    }
                    this.dvg_move_out2.DataSource = ds_temp.Tables[0];
                    ds_copy = ds_temp.Copy();
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
        }

        private string btn_delete()
        {
            if (str_type == "0")//保持原来不变
            {
                if (dvg_move_out.Rows.Count > 0)
                {
                    if (dvg_move_out.CurrentRow == null)
                    {
                        return "0";
                    }
                    #region 判断是否审核
                    DataRow[] dr_check = ds_move.Tables[0].Select("move_trans = '" + cbx_transaction_type.Text.Trim() + "'");
                    if (dr_check.Length > 0)
                    {

                    #endregion

                        DataTable dt_delete = new DataTable();
                        DataSet ds_del = new DataSet();
                        dt_delete.Columns.Add("sp_lineon");
                        dt_delete.Columns.Add("sp_pallet");
                        dt_delete.Columns.Add("sp_in_pallet");
                        dt_delete.Columns.Add("sp_batch");
                        dt_delete.Columns.Add("sp_sku");
                        dt_delete.Columns.Add("sp_use_qty");
                        dt_delete.Columns.Add("sp_use_qty_s");
                        dt_delete.Columns.Add("sp_outloc");
                        dt_delete.Columns.Add("sp_inloc");

                        for (int i = 0; i < dvg_move_out.Rows.Count; i++)
                        {
                            DataRow dr = dt_delete.NewRow();
                            dr["sp_lineon"] = dvg_move_out.Rows[i].Cells["move_line_no"].Value.ToString().Trim();
                            dr["sp_pallet"] = "";
                            dr["sp_in_pallet"] = "";
                            dr["sp_batch"] = "";
                            dr["sp_sku"] = dvg_move_out.Rows[i].Cells["sku"].Value.ToString().Trim();
                            dr["sp_use_qty"] = dvg_move_out.Rows[i].Cells["move_qty_m"].Value.ToString().Trim();
                            dr["sp_use_qty_s"] = dvg_move_out.Rows[i].Cells["move_qty_s"].Value.ToString().Trim();
                            dr["sp_outloc"] = dvg_move_out.Rows[i].Cells["moveout_location"].Value.ToString().Trim();
                            dr["sp_inloc"] = dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim();
                            dt_delete.Rows.Add(dr);
                        }
                        try
                        {
                            if (dt_delete.Rows.Count > 0)
                            {
                                ds_del.Tables.Add(dt_delete);
                                string str_message = "";
                                if (main.dbtype == "SQL")
                                {
                                    str_message = main.dbservice.Sql_exec_proc_movedel_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_del, main.g_user);
                                }
                                else
                                {
                                    str_message = main.dbservice.oracle_exec_proc_movedel_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_del, main.g_user);
                                }
                                if (str_message.Trim() != "")
                                {
                                    MessageBox.Show("删除失败" + str_message);
                                    return "0";
                                }
                                f_disply_detail(cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim());
                            }

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save !", main.g_info_dataset) + "!" + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return "0";
                        }
                    }
                }
            }
            else// 分配 到托盘批次
            {
                if (dvg_move_out2.Rows.Count > 0)
                {
                    if (dvg_move_out2.CurrentRow == null)
                    {
                        return "0";
                    }
                    #region 判断是否审核
                    DataRow[] dr_check = ds_move.Tables[0].Select("move_trans = '" + cbx_transaction_type.Text.Trim() + "'");
                    if (dr_check.Length > 0)
                    {

                    #endregion

                        DataTable dt_delete = new DataTable();
                        DataSet ds_del = new DataSet();
                        dt_delete.Columns.Add("sp_lineon");
                        dt_delete.Columns.Add("sp_pallet");
                        dt_delete.Columns.Add("sp_in_pallet");
                        dt_delete.Columns.Add("sp_batch");
                        dt_delete.Columns.Add("sp_sku");
                        dt_delete.Columns.Add("sp_use_qty");
                        dt_delete.Columns.Add("sp_use_qty_s");
                        dt_delete.Columns.Add("sp_outloc");
                        dt_delete.Columns.Add("sp_inloc");

                        for (int i = 0; i < dvg_move_out2.Rows.Count; i++)
                        {
                            DataRow dr = dt_delete.NewRow();
                            dr["sp_lineon"] = dvg_move_out2.Rows[i].Cells["move_line_no2"].Value.ToString().Trim();
                            dr["sp_pallet"] = dvg_move_out2.Rows[i].Cells["moveout_pallet2"].Value.ToString().Trim();
                            dr["sp_in_pallet"] = dvg_move_out2.Rows[i].Cells["movein_pallet2"].Value.ToString().Trim();
                            dr["sp_batch"] = dvg_move_out2.Rows[i].Cells["batchno2"].Value.ToString().Trim();
                            dr["sp_sku"] = dvg_move_out2.Rows[i].Cells["sku2"].Value.ToString().Trim();
                            dr["sp_use_qty"] = dvg_move_out2.Rows[i].Cells["move_qty_m2"].Value.ToString().Trim();
                            dr["sp_use_qty_s"] = dvg_move_out2.Rows[i].Cells["move_qty_s2"].Value.ToString().Trim();
                            dr["sp_outloc"] = dvg_move_out2.Rows[i].Cells["moveout_location2"].Value.ToString().Trim();
                            dr["sp_inloc"] = dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim();
                            dt_delete.Rows.Add(dr);
                        }
                        try
                        {
                            if (dt_delete.Rows.Count > 0)
                            {
                                ds_del.Tables.Add(dt_delete);
                                string str_message = "";
                                if (main.dbtype == "SQL")
                                {
                                    str_message = main.dbservice.Sql_exec_proc_movedel_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_del, main.g_user);
                                }
                                else
                                {
                                    str_message = main.dbservice.oracle_exec_proc_movedel_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_del, main.g_user);
                                }
                                if (str_message.Trim() != "")
                                {
                                    MessageBox.Show("删除失败" + str_message);
                                    return "0";
                                }
                                f_disply_detail(cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim());
                            }

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save !", main.g_info_dataset) + "!" + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return "0";
                        }
                    }
                }
            }
            return "1";
        }
        #endregion
        public void ClearCntrValue(Control parContainer, bool bol, string edit)
        {
            for (int index = 0; index < parContainer.Controls.Count; index++)
            {
                // 如果是容器类控件，递归调用自己
                if (parContainer.Controls[index].HasChildren)
                {
                    // ClearCntrValue(parContainer.Controls[index]);
                }
                else
                {
                    switch (parContainer.Controls[index].GetType().Name)
                    {

                        case "TextBox":

                            if (edit != "1")
                            {
                                parContainer.Controls[index].Text = "";
                            }

                            if (bol == false)
                                ((TextBox)parContainer.Controls[index]).ReadOnly = true;
                            else
                                ((TextBox)parContainer.Controls[index]).ReadOnly = false;
                            break;
                        case "RadioButton":
                            if (edit != "1")
                                ((RadioButton)(parContainer.Controls[index])).Checked = false;
                            ((RadioButton)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "CheckBox":
                            if (edit != "1")
                                ((CheckBox)(parContainer.Controls[index])).Checked = false;

                            ((CheckBox)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "ComboBox":
                            if (edit != "1")
                                ((ComboBox)(parContainer.Controls[index])).Text = "";
                            ((ComboBox)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "DateTimePicker":
                            if (edit != "1")
                                ((DateTimePicker)(parContainer.Controls[index])).Text = "";
                            ((DateTimePicker)(parContainer.Controls[index])).Enabled = bol;
                            break;
                    }

                }
            }
            if (edit == "1")
            {
                cbx_h_consignor.Enabled = false;

            }
            cb_h_move_status.SelectedIndex = 0;
            cb_h_move_status.Enabled = false;
            this.cb_move_type.SelectedIndex = 0;
            cb_move_type.Enabled = false;
            tb_h_move_no.ReadOnly = true;
            tb_h_consignor_name.ReadOnly = true;
        }

        private void btn_Query_Click(object sender, EventArgs e)
        {
            str_sql_where = " where a.inv_org = '" + main.g_org + "' and a.move_type='0' and  a.main_dist<>'D' ";

            if (tb_cusname.Text.ToString().Trim() == "" && cb_consignor.Text.ToString().Trim() != "")
            {
                return;
            }
            if (cb_consignor.Text.ToString().Trim() != "")
            {
                str_sql_where += " and a.consignor='" + cb_consignor.Text.ToString().Trim() + "' ";
            }
            else
            {
                str_sql_where += " and  a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
            }
            if (cbx_transaction_type_Q.Text.Trim() != "")
            {
                str_sql_where += " and a.standby_5='" + cbx_transaction_type_Q.SelectedValue.ToString().Trim() + "' ";
            }
            if (tb_move_no.Text.ToString().Trim() != "")
            {
                str_sql_where += " and a.move_no='" + tb_move_no.Text.ToString().Trim() + "' ";
            }
            if (dtp_made_time.Text.ToString().Trim() != "" | dtp_made_time_end.Text.ToString().Trim() != "")
            {
                if (main.dbtype == "SQL")
                    str_sql_where += " and  CONVERT(varchar(10) , a.made_time, 102 )  between     '" + dtp_made_time.Text.Trim() + "' and '" + dtp_made_time_end.Text + "'";
                else
                    str_sql_where += " and to_char(a.made_time,'yyyy.mm.dd')  between     '" + dtp_made_time.Text.Trim() + "' and '" + dtp_made_time_end.Text + "'";
            }
            str_sql_where += "and a.move_status ='0' order by move_no";
            if (main.dbtype == "SQL")
            {
                str_sql = "select consignor_name,a.*,case rtrim(ltrim(a.standby_5)) when '01' then '" + main.g_class.comm_getchangestring("import store", main.g_info_dataset) + "' when '02' then '" + main.g_class.comm_getchangestring("borrow store", main.g_info_dataset) + "' when '03' then '" + main.g_class.comm_getchangestring("kanban store", main.g_info_dataset) + "' else '" + main.g_class.comm_getchangestring("move", main.g_info_dataset) + "' end  transaction_type2,a.standby_5 transaction_type  from " + main.g_space + ".inv_move_header  a left join wms.mst_customer b on a.inv_org = b.inv_org and a.consignor=b.consignor  " + str_sql_where;
            }
            else
            {
                str_sql = "select consignor_name,a.*,case trim(a.standby_5) when '01' then '" + main.g_class.comm_getchangestring("import store", main.g_info_dataset) + "' when '02' then '" + main.g_class.comm_getchangestring("borrow store", main.g_info_dataset) + "' when '03' then '" + main.g_class.comm_getchangestring("kanban store", main.g_info_dataset) + "' else '" + main.g_class.comm_getchangestring("move", main.g_info_dataset) + "' end  transaction_type2,a.standby_5 transaction_type  from " + main.g_space + ".inv_move_header  a left join wms.mst_customer b on a.inv_org = b.inv_org and a.consignor=b.consignor  " + str_sql_where;
            }
            try
            {
                if (main.dbtype == "SQL")
                {
                    dsmove_header = main.dbservice.Sql_exec_selectsql(str_sql);
                }
                else
                {
                    dsmove_header = main.dbservice.oracle_exec_selectsql(str_sql);
                }
                dvg_move.DataSource = dsmove_header.Tables[0];
                if (dsmove_header.Tables[0].Rows.Count > 0)
                {
                    show(dsmove_header.Tables[0].Rows[0]);
                    f_disply_detail(dsmove_header.Tables[0].Rows[0]["consignor"].ToString().Trim(), dsmove_header.Tables[0].Rows[0]["move_no"].ToString().Trim());
                    this.btn_new_d.Enabled = true;
                    this.btn_modi_d.Enabled = true;
                    this.btn_del_d.Enabled = true;
                    this.btn_cancel_d.Enabled = false;
                    this.dvg_move_out.Enabled = true;
                    this.btn_save_d.Enabled = false;

                }
                else
                {
                    ClearCntrValue(this.groupBox3, false, "0");
                    ClearCntrValue(this.groupBox4, false, "0");

                    this.dvg_move_out.DataSource = null;
                    this.dvg_move_out2.DataSource = null;
                }
            }
            catch (System.Exception ee)
            {

                MessageBox.Show(main.g_class.comm_getchangestring("Fail to Query", main.g_info_dataset) + "!" + ee.ToString());
            }

        }


        private void show(DataRow tr)
        {
            this.cbx_h_consignor.Text = tr["consignor"].ToString().Trim();
            this.tb_h_consignor_name.Text = tr["consignor_name"].ToString().Trim();
            this.cb_move_type.SelectedIndex = Convert.ToInt32(tr["move_type"].ToString().Trim());
            this.tb_h_move_no.Text = tr["move_no"].ToString().Trim();
            this.tb_h_memo.Text = tr["memo"].ToString().Trim();
            cbx_transaction_type.SelectedValue = tr["transaction_type"].ToString().Trim();
            cb_h_move_status.SelectedIndex = Convert.ToInt32(tr["move_status"].ToString().Trim());

        }

        private void w_inv003_Load(object sender, EventArgs e)
        {
            //初始化变量
            dscustomer = new DataSet();
            // asnclass = new common_class();
            string str_common = "";
            DataSet ds_move_reason = null;
            ArrayList al_cbx = new ArrayList();
            int i_cbx;
            try
            {
                dscustomer = new DataSet();
                dscustomer = main.g_class.comm_get_consignor();
                cb_consignor.DataSource = dscustomer.Tables[0];
                cb_consignor.ValueMember = "consignor";
                cb_consignor.DisplayMember = "consignor";
                dscustomer1 = new DataSet();
                dscustomer1 = dscustomer.Copy();
                cbx_h_consignor.DataSource = dscustomer1.Tables[0];
                cbx_h_consignor.ValueMember = "consignor";
                cbx_h_consignor.DisplayMember = "consignor";

                if (main.dbtype == "SQL")
                {
                    str_common = "select dictionary_code,case use_flag when '1' then content1 when '2' then content2 when '3' then convert(char,number1) else convert(char,number2) end as move_reason from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and ltrim(rtrim(dictionary_name))='move_reason' order by dictionary_code";
                    ds_move_reason = main.dbservice.Sql_exec_selectsql(str_common);
                }
                else
                {
                    str_common = "select dictionary_code,case use_flag when '1' then content1 when '2' then content2 when '3' then to_char(number1) else to_char(number2) end as move_reason from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and trim(dictionary_name)='move_reason' order by dictionary_code";
                    ds_move_reason = main.dbservice.oracle_exec_selectsql(str_common);
                }
                int i_ds;
                i_ds = ds_move_reason.Tables[0].Rows.Count;
                if (i_ds > 0)
                {
                    for (int i = 0; i < i_ds; i++)
                    {
                        ds_move_reason.Tables[0].Rows[i]["move_reason"] = main.g_class.comm_getchangestring(ds_move_reason.Tables[0].Rows[i]["move_reason"].ToString().Trim(), main.g_info_dataset);
                        ds_move_reason.Tables[0].Rows[i]["dictionary_code"] = main.g_class.comm_getchangestring(ds_move_reason.Tables[0].Rows[i]["dictionary_code"].ToString().Trim(), main.g_info_dataset);
                    }
                }
                // DataSet newf_ds = ds_type.Copy();

                DataRow dr = ds_move_reason.Tables[0].NewRow();
                dr["dictionary_code"] = "";
                dr["move_reason"] = "";
                ds_move_reason.Tables[0].Rows.Add(dr);
                cbx_h_move_reason.DataSource = ds_move_reason.Tables[0];
                cbx_h_move_reason.ValueMember = "dictionary_code";
                cbx_h_move_reason.DisplayMember = "move_reason";
                cbx_h_move_reason.Text = "";

                i_cbx = cb_move_type.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cb_move_type.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cb_move_type.Items[i].ToString().Trim(), main.g_info_dataset));
                    }
                    //清除cbx_bookstatus
                    cb_move_type.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cb_move_type.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                }
                i_cbx = cb_h_move_status.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cb_h_move_status.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cb_h_move_status.Items[i].ToString().Trim(), main.g_info_dataset));
                    }
                    //清除cbx_bookstatus
                    cb_h_move_status.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cb_h_move_status.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                }

                main.g_class.comm_changeCbxContent(cb_move_type, main.g_info_dataset, '1');
                main.g_class.comm_changeControl(this, main.g_win_dataset);
                ClearCntrValue(this.groupBox3, false, "1");

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Consignor's Information!", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
            try
            {
                string str_sql2 = "";

                if (main.dbtype == "SQL")
                {
                    str_sql2 = "select isnull(id_data,'') from " + main.g_space + ".sys_parameter where inv_org='" + main.g_org + "'and id=8902";
                    g_str_loctype = main.dbservice.Sql_exec_selectstring(str_sql2).Trim();
                }
                else
                {
                    str_sql2 = "select nvl(id_data,'') from " + main.g_space + ".sys_parameter where inv_org='" + main.g_org + "'and id=8902";
                    g_str_loctype = main.dbservice.oracle_exec_selectstring(str_sql2).Trim();
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
            //获取移库是否可以不同仓
            try
            {
                string str_sql2 = "select id_data from " + main.g_space + ".sys_parameter where inv_org='" + main.g_org + "'and id=8005";
                if (main.dbtype == "SQL")
                {
                    str_warehouse = main.dbservice.Sql_exec_selectstring(str_sql2).Trim();
                }
                else
                {
                    str_warehouse = main.dbservice.oracle_exec_selectstring(str_sql2).Trim();
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
            //对日期控件Format
            dtp_made_time.CustomFormat = "yyyy.MM.dd";
            dtp_made_time.Format = DateTimePickerFormat.Custom;
            dtp_made_time_end.CustomFormat = "yyyy.MM.dd";
            dtp_made_time_end.Format = DateTimePickerFormat.Custom;
            dtp_made_time.Value = System.Convert.ToDateTime(DateTime.Now.ToString("yyyy.MM.dd").Trim());
            dtp_made_time_end.Value = System.Convert.ToDateTime(DateTime.Now.AddDays(7).ToString("yyyy.MM.dd").Trim());
            //获取按钮权限
            string str_right;
            str_right = main.g_class.comm_getright("w_inv003", main.g_right_dataset);
            //新增
            if (str_right.Substring(0, 1) == "0")
            {
                btn_new.Visible = false;
                btn_new_d.Visible = false;
            }
            else
            {
                btn_new.Visible = true;
                btn_new_d.Visible = true;
            }
            //修改
            if (str_right.Substring(1, 1) == "0")
            {
                btn_modi.Visible = false;
                btn_modi_d.Visible = false;
            }
            else
            {
                btn_modi.Visible = true;
                btn_modi_d.Visible = true;
            }
            //删除

            if (str_right.Substring(2, 1) == "0")
            {
                btn_del.Visible = false;
                btn_del_d.Visible = false;
            }
            else
            {
                btn_del.Visible = true;
                btn_del_d.Visible = true;
            }
            //保存，取消
            if (str_right.Substring(3, 1) == "0")
            {
                btn_save.Visible = false;
                btn_cancel.Visible = false;
                btn_save_d.Visible = false;
                btn_cancel_d.Visible = false;
            }
            else
            {
                btn_save.Visible = true;
                btn_cancel.Visible = true;
                btn_save_d.Visible = true;
                btn_cancel_d.Visible = true;
            }
            //初始化交易类型
            try
            {
                DataSet f_ds;
                f_ds = main.g_class.comm_get_dictionary("move_trans");
                //进行语言转换
                int i_ds;
                i_ds = f_ds.Tables[0].Rows.Count;
                if (i_ds > 0)
                {
                    for (int i = 0; i < i_ds; i++)
                    {
                        f_ds.Tables[0].Rows[i]["move_trans"] = main.g_class.comm_getchangestring(f_ds.Tables[0].Rows[i]["move_trans"].ToString().Trim(), main.g_info_dataset);
                    }
                }

                ds_move = f_ds.Copy();
                cbx_transaction_type.ValueMember = "dictionary_code";
                cbx_transaction_type.DisplayMember = "move_trans";
                cbx_transaction_type.DataSource = f_ds.Tables[0].Copy();
                DataSet ds_new = f_ds.Copy();
                ds_new.Tables[0].Rows.Clear();
                DataRow drnew;
                drnew = ds_new.Tables[0].NewRow();
                drnew["dictionary_code"] = "";
                drnew["move_trans"] = "";
                ds_new.Tables[0].Rows.Add(drnew);
                for (int i = 0; i < f_ds.Tables[0].Rows.Count; i++)
                {
                    DataRow drnew2;
                    drnew2 = ds_new.Tables[0].NewRow();
                    drnew2["dictionary_code"] = f_ds.Tables[0].Rows[i]["dictionary_code"].ToString().Trim();
                    drnew2["move_trans"] = f_ds.Tables[0].Rows[i]["move_trans"].ToString().Trim();
                    ds_new.Tables[0].Rows.Add(drnew2);
                }
                cbx_transaction_type_Q.ValueMember = "dictionary_code";
                cbx_transaction_type_Q.DisplayMember = "move_trans";
                cbx_transaction_type_Q.DataSource = ds_new.Tables[0].Copy();

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize Information of bill's type", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }

            //绑定仓库
            try
            {
                DataSet ds_warehouse;
                str_common = "select warehouse,warehouse_name  from " + main.g_space + ".mst_warehouse where main_dist <> 'D' and inv_org ='" + main.g_org.Trim() + "'";
                if (main.dbtype == "SQL")
                {
                    ds_warehouse = main.dbservice.Sql_exec_selectsql(str_common);
                }
                else
                {
                    ds_warehouse = main.dbservice.oracle_exec_selectsql(str_common);
                }
                DataGridViewComboBoxColumn dgvComboBoxColumn = dvg_move_out.Columns[1] as DataGridViewComboBoxColumn;
                //dgvComboBoxColumn.DataPropertyName = "transaction_type";               
                dgvComboBoxColumn.DataSource = ds_warehouse.Tables[0].Copy();//必须在设置dataGridView1的DataSource的属性前设置
                dgvComboBoxColumn.DisplayMember = "warehouse_name";
                dgvComboBoxColumn.ValueMember = "warehouse";

                DataGridViewComboBoxColumn dgvComboBoxColumn2 = dvg_move_out.Columns[10] as DataGridViewComboBoxColumn;
                //dgvComboBoxColumn.DataPropertyName = "transaction_type";                
                dgvComboBoxColumn2.DataSource = ds_warehouse.Tables[0].Copy();//必须在设置dataGridView1的DataSource的属性前设置
                dgvComboBoxColumn2.DisplayMember = "warehouse_name";
                dgvComboBoxColumn2.ValueMember = "warehouse";


                DataGridViewComboBoxColumn dgvComboBoxColumn3 = dvg_move_out2.Columns[2] as DataGridViewComboBoxColumn;
                //dgvComboBoxColumn.DataPropertyName = "transaction_type";               
                dgvComboBoxColumn3.DataSource = ds_warehouse.Tables[0].Copy();//必须在设置dataGridView1的DataSource的属性前设置
                dgvComboBoxColumn3.DisplayMember = "warehouse_name";
                dgvComboBoxColumn3.ValueMember = "warehouse";

                DataGridViewComboBoxColumn dgvComboBoxColumn4 = dvg_move_out2.Columns[11] as DataGridViewComboBoxColumn;
                //dgvComboBoxColumn.DataPropertyName = "transaction_type";                
                dgvComboBoxColumn4.DataSource = ds_warehouse.Tables[0].Copy();//必须在设置dataGridView1的DataSource的属性前设置
                dgvComboBoxColumn4.DisplayMember = "warehouse_name";
                dgvComboBoxColumn4.ValueMember = "warehouse";

                //绑定移出仓库
                //cbx_from_warehouse.DataSource = ds_warehouse.Tables[0];
                //cbx_from_warehouse.ValueMember = "warehouse";
                //cbx_from_warehouse.DisplayMember = "warehouse_name";
                ////绑定移入仓库
                //cbx_to_warehouse.DataSource = ds_warehouse.Tables[0].Copy();
                //cbx_to_warehouse.ValueMember = "warehouse";
                //cbx_to_warehouse.DisplayMember = "warehouse_name";
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get warehouse's Information!", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
            //获取分配是到库位还是到批次
            try
            {

                if (main.dbtype == "SQL")
                {
                    string str_sql2 = "select ltrim(rtrim(isnull(max(id_data),'0')))  from " + main.g_space + ".Sys_Parameter where inv_org = '" + main.g_org + "' and id = 8201";
                    str_type = main.dbservice.Sql_exec_selectstring(str_sql2).Trim();
                }
                else
                {
                    string str_sql2 = "select trim(nvl(max(id_data),'0'))  from " + main.g_space + ".Sys_Parameter where inv_org = '" + main.g_org + "' and id = 8201";
                    str_type = main.dbservice.oracle_exec_selectstring(str_sql2).Trim();
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
            if (str_type == "0")
            {
                dvg_move_out.Dock = DockStyle.Fill;
                dvg_move_out.Visible = true;
                dvg_move_out2.Visible = false;
            }
            else
            {
                dvg_move_out2.Dock = DockStyle.Fill;
                dvg_move_out2.Visible = true;
                dvg_move_out.Visible = false;
            }

            if (main.dbtype == "SQL")
            {
                str_sql = "select consignor_name,a.*,case rtrim(ltrim(a.standby_5)) when '01' then '保税料' when '02' then '借还料' else '移库' end  transaction_type  from " + main.g_space + ".inv_move_header  a  ," + main.g_space + ".mst_customer b where a.inv_org = b.inv_org and a.consignor=b.consignor and 1=2 ";
            }
            else
            {
                str_sql = "select consignor_name,a.*,case trim(a.standby_5) when '01' then '保税料' when '02' then '借还料' else '移库' end  transaction_type  from " + main.g_space + ".inv_move_header  a, " + main.g_space + ".mst_customer b where a.inv_org = b.inv_org and a.consignor=b.consignor  and 1=2";
            }
            try
            {
                if (main.dbtype == "SQL")
                {
                    dsmove_header = main.dbservice.Sql_exec_selectsql(str_sql);

                }
                else
                {
                    dsmove_header = main.dbservice.oracle_exec_selectsql(str_sql);
                }
                dvg_move.DataSource = dsmove_header.Tables[0];
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to Query", main.g_info_dataset) + "!" + ee.ToString());
            }

        }

        private void cb_consignor_TextChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cb_consignor.Text.Trim();
            tb_cusname.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }
        //判断库位是否可移

        //判断sku是否存在

        private void cbx_h_consignor_TextChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cbx_h_consignor.Text.Trim();
            tb_h_consignor_name.Text = main.g_class.comm_findname(str_cust, dscustomer1);
        }

        private void btn_new_Click(object sender, EventArgs e)
        {
            coint = 1;
            this.btn_new.Enabled = false;
            this.btn_cancel.Enabled = true;
            this.dvg_move.Enabled = false;
            this.btn_save.Enabled = true;
            this.btn_modi.Enabled = false;
            this.btn_del.Enabled = false;

            this.btn_new_d.Enabled = false;
            this.btn_cancel_d.Enabled = false;

            this.btn_save_d.Enabled = false;
            this.btn_modi_d.Enabled = false;
            this.btn_del_d.Enabled = false;

            btn_new_d.Enabled = false;
            btn_modi_d.Enabled = false;
            btn_del_d.Enabled = false;



            ClearCntrValue(this.groupBox3, true, "0");
            //ClearCntrValue(this.groupBox2, true, "0");
            cb_move_type.Text = main.g_class.comm_getchangestring("move", main.g_info_dataset);
            cb_h_move_status.SelectedIndex = 0;
            this.tb_h_move_no.Text = main.g_class.comm_getaccountno("move_no");
            if (cbx_h_consignor.Items.Count == 1)
            {
                cbx_h_consignor.Text = dscustomer.Tables[0].Rows[0]["consignor"].ToString().Trim();
            }
            if (cb_h_move_status.Items.Count > 0)
            {
                cb_h_move_status.SelectedIndex = 0;
            }
            dvg_move_out.DataSource = null;

        }




        private void btn_modi_Click(object sender, EventArgs e)
        {
            if (tb_h_move_no.Text.Trim() == "")
            {
                MessageBox.Show("必须选择一个移库单修改！");
                return;
            }
            if (cb_h_move_status.Text.Trim() == "Confirm")
            {

                MessageBox.Show(main.g_class.comm_getchangestring("The bill of move can't modify because it has been confirmed ", main.g_info_dataset) + "!");
                return;
            }
            #region 判断是否审核
            DataRow[] dr_check = ds_move.Tables[0].Select("move_trans = '" + cbx_transaction_type.Text.Trim() + "'");
            if (dr_check.Length > 0)
            {
                if (dr_check[0]["content2"].ToString().Trim() == "1")//需要审核
                {
                    DataSet ds_con;
                    string str_sql = "select standby_4 From " + main.g_space + ".inv_move_header  where inv_org='" + main.g_org + "' and consignor='" + cbx_h_consignor.Text.Trim() + "' and move_no='" + tb_h_move_no.Text.Trim() + "'";
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            ds_con = main.dbservice.Sql_exec_selectsql(str_sql);
                        }
                        else
                        {
                            ds_con = main.dbservice.oracle_exec_selectsql(str_sql);
                        }

                        if (ds_con.Tables[0].Rows.Count > 0)
                        {
                            if (ds_con.Tables[0].Rows[0]["standby_4"].ToString().Trim() == "1")
                            {
                                MessageBox.Show("当前单据已经审核，不能在修改");
                                return;
                            }
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(ee.ToString());
                        return;
                    }
                }
            #endregion
            }

            coint = 2;
            this.btn_new.Enabled = false;
            this.btn_cancel.Enabled = true;
            this.dvg_move.Enabled = false;
            this.btn_save.Enabled = true;
            this.btn_modi.Enabled = false;
            this.btn_del.Enabled = true;

            btn_new_d.Enabled = false;
            btn_modi_d.Enabled = false;
            btn_del_d.Enabled = false;
            ClearCntrValue(this.groupBox3, true, "1");

        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            string str_temp = "", str_move = "";
            if (cbx_h_consignor.Text == "")
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Please choose a consignor", main.g_info_dataset));
                return;
            }

            if (coint == 1)
            {
                DataRow[] dr_check = ds_move.Tables[0].Select("move_trans = '" + cbx_transaction_type.Text.Trim() + "'");
                if (dr_check.Length > 0)
                {
                    if (dr_check[0]["content2"].ToString().Trim() == "1")
                    {
                        str_move = "0";
                    }
                    else
                    {
                        str_move = "1";
                    }
                }
                else
                {
                    str_move = "1";
                }

                str_sql = "insert into " + main.g_space + ".inv_move_header(inv_org,consignor,move_no,move_type,move_reason,move_status,memo,main_dist,made_time,maker,standby_5,standby_4) values(" +
                    "'" + main.g_org + "','" + cbx_h_consignor.Text.Trim() + "','" + tb_h_move_no.Text.Trim() + "','" + cb_move_type.SelectedIndex + "','" + cbx_h_move_reason.SelectedIndex + "','" + cb_h_move_status.SelectedIndex + "','" + tb_h_memo.Text.Trim() + "','A',";

                if (main.dbtype == "SQL")
                {

                    str_temp = str_temp + "getdate(),'";
                }
                else
                {

                    str_temp = str_temp + " sysdate,'";
                }
                str_temp = str_temp + main.g_user + "','" + cbx_transaction_type.SelectedValue.ToString().Trim() + "','" + str_move.Trim() + "')";
                try
                {
                    str_sql += str_temp;
                    if (main.dbtype == "SQL")
                    {
                        main.dbservice.Sql_exec_commandsql(str_sql);
                    }
                    else
                    {
                        main.dbservice.oracle_exec_commandsql(str_sql);
                    }
                    //btn_Query_Click(sender, new EventArgs());
                    //新增一行
                    DataRow newdr = ((DataTable)dvg_move.DataSource).NewRow();
                    newdr["consignor"] = cbx_h_consignor.Text.Trim();
                    newdr["move_no"] = tb_h_move_no.Text.Trim();
                    newdr["move_type"] = cb_move_type.SelectedIndex;
                    newdr["transaction_type"] = cbx_transaction_type.SelectedValue.ToString().Trim();
                    newdr["made_time"] = DateTime.Now.ToString(); ;
                    newdr["maker"] = main.g_username;
                    newdr["inv_org"] = main.g_org;
                    newdr["move_status"] = cb_h_move_status.SelectedIndex;

                    ((DataTable)dvg_move.DataSource).Rows.Add(newdr);
                    //选中这一行
                    //dvg_move.Rows[dvg_move.CurrentRow.Index].Selected = false;
                    for (int i = 0; i < dvg_move.Rows.Count; i++)
                    {
                        dvg_move.Rows[i].Selected = false;
                    }
                    dvg_move.Rows[dvg_move.RowCount - 1].Selected = true;
                    dvg_move_out.DataSource = null;

                    str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dvg_move.Rows[dvg_move.RowCount - 1].Cells["consignor"].Value.ToString().Trim() + "'and move_no='" + dvg_move.Rows[dvg_move.RowCount - 1].Cells["move_no"].Value.ToString().Trim() + "'";
                    DataRow[] tr = dsmove_header.Tables[0].Select(str_sql_where);
                    if (tr.Length > 0)
                    {
                        show(tr[0]);
                        f_disply_detail(tr[0]["consignor"].ToString().Trim(), tr[0]["move_no"].ToString().Trim());
                    }
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to save!", main.g_info_dataset) + "!" + ee.ToString());//保存移库表头信息失败
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
            else if (coint == 2)
            {
                if (main.dbtype == "SQL")
                {
                    str_temp = str_temp + "update_time=getdate(),";
                }
                else
                {
                    str_temp = str_temp + "update_time= sysdate,";
                }
                str_temp = str_temp + "updater='" + main.g_user + "' where inv_org = '" + main.g_org + "' and  consignor='" + cbx_h_consignor.Text.Trim() + "' and move_no='" + tb_h_move_no.Text.Trim() + "'";
                str_sql = "update " + main.g_space + ".inv_move_header set move_reason='" + cbx_h_move_reason.SelectedIndex + "',memo='" + tb_h_memo.Text.Trim() + "',main_dist='U',standby_5='" + cbx_transaction_type.SelectedValue.ToString().Trim() + "'," + str_temp;
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        main.dbservice.Sql_exec_commandsql(str_sql);
                    }
                    else
                    {
                        main.dbservice.oracle_exec_commandsql(str_sql);
                    }
                    //btn_Query_Click(sender, new EventArgs());

                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring(" Fail to modify information of moving confirmation", main.g_info_dataset) + "!" + ee.ToString());//修改移库表头信息失败
                    Cursor.Current = Cursors.Default;
                    return;
                }

            }
            this.btn_new.Enabled = true;
            this.btn_cancel.Enabled = false;
            this.btn_save.Enabled = false;
            this.btn_modi.Enabled = true;
            this.btn_del.Enabled = true;

            this.dvg_move.Enabled = true;
            this.btn_new_d.Enabled = true;
            this.btn_cancel_d.Enabled = false;

            this.btn_save_d.Enabled = false;
            this.btn_modi_d.Enabled = true;
            this.btn_del_d.Enabled = true;
            ClearCntrValue(this.groupBox3, false, "1");

        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.btn_new.Enabled = true;
            this.btn_cancel.Enabled = false;
            this.btn_save.Enabled = false;
            this.btn_modi.Enabled = true;
            this.btn_del.Enabled = true;
            this.dvg_move.Enabled = true;
            ClearCntrValue(this.groupBox3, false, "1");
            //明细按钮
            btn_new_d.Enabled = true;
            btn_modi_d.Enabled = true;
            btn_del_d.Enabled = true;
            if (dvg_move.CurrentRow != null)
            {
                //str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dvg_move.Rows[dvg_move.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "'and move_no='" + dvg_move.Rows[dvg_move.CurrentRow.Index].Cells["move_no"].Value.ToString().Trim() + "'";
                //str_sql = "select * from " + main.g_space + ".inv_move_detail where   main_dist<>'D' and move_status='0' and " + str_sql_where;
                //DataRow[] tr = dsmove_header.Tables[0].Select(str_sql_where);
                //if (tr.Length > 0)
                //{
                //    show(tr[0]);
                //    try
                //    {
                //        if (main.dbtype == "SQL")
                //        {
                //            dsmove_out = main.dbservice.Sql_exec_selectsql(str_sql);
                //        }
                //        else
                //        {
                //            dsmove_out = main.dbservice.oracle_exec_selectsql(str_sql);
                //        }
                //        this.dvg_move_out.DataSource = dsmove_out.Tables[0];
                //        if (dvg_move_out.Rows.Count == 0)
                //        {

                //        }
                //        else
                //        {
                //            show_out(dsmove_out.Tables[0].Rows[0]);
                //        }
                //    }
                //    catch (System.Exception ee)
                //    {

                //        MessageBox.Show(main.g_class.comm_getchangestring("Fail to Query", main.g_info_dataset) + "!" + ee.ToString());
                //    }
                //}
            }
        }

        //private void btn_Confirm_Click(object sender, EventArgs e)
        //{
        //    if (cbx_h_consignor.Text.Trim() != "" && tb_h_move_no.Text.Trim() != "")
        //    { 
        //        string str_temp = "";
        //        if (main.dbtype == "SQL")
        //        {
        //            str_temp = str_temp + "confirm_day=getdate(),";
        //        }
        //        else
        //        {
        //            str_temp = str_temp + "confirm_day=sysdate,";
        //        }
        //        str_temp = str_temp + "confirmer='" + main.g_user + "' where consignor='" + cbx_h_consignor.Text.Trim() + "' and move_no='" + tb_h_move_no.Text.Trim() + "'";

        //        str_sql = "update " + main.g_space + ".inv_move_header set " + str_temp;
        //        try
        //        {
        //            if (main.dbtype == "SQL")
        //            {
        //                main.dbservice.Sql_exec_commandsql(str_sql);
        //            }
        //            else
        //            {
        //                main.dbservice.oracle_exec_commandsql(str_sql);
        //            }
        //            btn_Query_Click(sender, new EventArgs());

        //        }
        //        catch (System.Exception ee)
        //        {
        //            MessageBox.Show(main.g_class.comm_getchangestring("Move database header information to confirm failure!" + ee.ToString());//确认移库表头信息失败
        //            Cursor.Current = Cursors.Default;
        //            return;
        //        }
        //    }

        //}

        private void btn_del_Click(object sender, EventArgs e)
        {
            if (tb_h_move_no.Text.Trim() == "")
            {
                MessageBox.Show("必须选择一个移库单！");
                return;
            }
            string str_sql = "";
            if (cb_h_move_status.Text.Trim() == "Confirm")
            {

                MessageBox.Show(main.g_class.comm_getchangestring("The bill of move can't delete detail because it has been confirmed ", main.g_info_dataset) + "!");
                return;
            }
            if (dvg_move.RowCount > 0)
            {

                if (MessageBox.Show(main.g_class.comm_getchangestring("Are you sure to delete bill", main.g_info_dataset), "Information", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    //删除明细
                    if (btn_delete() == "0")
                    {
                        return;
                    }
                    str_sql = "delete from  " + main.g_space + ".inv_move_header  where inv_org = '" + main.g_org + "' and consignor='" + dvg_move.Rows[dvg_move.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "'and move_no='" + dvg_move.Rows[dvg_move.CurrentRow.Index].Cells["move_no"].Value.ToString().Trim() + "'";
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            main.dbservice.Sql_exec_commandsql(str_sql);
                        }
                        else
                        {
                            main.dbservice.oracle_exec_commandsql(str_sql);
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to save", main.g_info_dataset) + "!" + ee.ToString());
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                    btn_Query_Click(sender, new EventArgs());
                }
            }

        }

        private void btn_new_d_Click(object sender, EventArgs e)
        {
            if (tb_h_move_no.Text.Trim() == "")
            {
                MessageBox.Show("必须选择一个移库单才能增加明细！");
                return;
            }
            if (dvg_move.CurrentRow != null)
            {
                #region 判断是否审核
                DataRow[] dr_check = ds_move.Tables[0].Select("move_trans = '" + cbx_transaction_type.Text.Trim() + "'");
                if (dr_check.Length > 0)
                {
                    if (dr_check[0]["content2"].ToString().Trim() == "1")//需要审核
                    {
                        DataSet ds_con;
                        string str_sql = "select standby_4 From " + main.g_space + ".inv_move_header  where inv_org='" + main.g_org + "' and consignor='" + cbx_h_consignor.Text.Trim() + "' and move_no='" + tb_h_move_no.Text.Trim() + "'";
                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                ds_con = main.dbservice.Sql_exec_selectsql(str_sql);
                            }
                            else
                            {
                                ds_con = main.dbservice.oracle_exec_selectsql(str_sql);
                            }

                            if (ds_con.Tables[0].Rows.Count > 0)
                            {
                                if (ds_con.Tables[0].Rows[0]["standby_4"].ToString().Trim() == "1")
                                {
                                    MessageBox.Show("当前单据已经审核，不能在修改");
                                    return;
                                }
                            }
                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(ee.ToString());
                            return;
                        }
                    }
                #endregion

                    w_inv003_add inv003 = new w_inv003_add();
                    w_inv003_add.str_consignor = cbx_h_consignor.Text.Trim();
                    w_inv003_add.str_move_no = tb_h_move_no.Text.Trim();
                    inv003.ShowDialog();
                    f_disply_detail(cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim());
                }
            }
        }
        private void btn_modi_d_Click(object sender, EventArgs e)
        {
            if (str_type == "0")
            {
                if (dvg_move_out.Rows.Count > 0)
                {
                    #region 判断是否审核
                    DataRow[] dr_check = ds_move.Tables[0].Select("move_trans = '" + cbx_transaction_type.Text.Trim() + "'");
                    if (dr_check.Length > 0)
                    {
                        if (dr_check[0]["content2"].ToString().Trim() == "1")//需要审核
                        {
                            DataSet ds_con;
                            string str_sql = "select standby_4 From " + main.g_space + ".inv_move_header  where inv_org='" + main.g_org + "' and consignor='" + cbx_h_consignor.Text.Trim() + "' and move_no='" + tb_h_move_no.Text.Trim() + "'";
                            try
                            {
                                if (main.dbtype == "SQL")
                                {
                                    ds_con = main.dbservice.Sql_exec_selectsql(str_sql);
                                }
                                else
                                {
                                    ds_con = main.dbservice.oracle_exec_selectsql(str_sql);
                                }

                                if (ds_con.Tables[0].Rows.Count > 0)
                                {
                                    if (ds_con.Tables[0].Rows[0]["standby_4"].ToString().Trim() == "1")
                                    {
                                        MessageBox.Show("当前单据已经审核，不能在修改");
                                        return;
                                    }
                                }
                            }
                            catch (System.Exception ee)
                            {
                                MessageBox.Show(ee.ToString());
                                return;
                            }
                        }
                    #endregion
                        dvg_move_out.ReadOnly = false;
                        for (int i = 0; i < dvg_move_out.Rows.Count; i++)
                        {
                            dvg_move_out.Rows[i].Cells["move_line_no"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["moveout_warehouse"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["moveout_location"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["sku"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["sku_name"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["move_qty_s"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["stock_qty_m"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["stock_qty_s"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["move_cubage"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["move_gross_weight"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["move_net_weight"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["cubage"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["gross_weight"].ReadOnly = true;
                            dvg_move_out.Rows[i].Cells["net_weight"].ReadOnly = true;


                            dvg_move_out.Rows[i].Cells["move_qty_m"].ReadOnly = false;
                            dvg_move_out.Rows[i].Cells["movein_warehouse"].ReadOnly = false;
                            dvg_move_out.Rows[i].Cells["movein_location"].ReadOnly = false;
                        }
                        btn_save_d.Enabled = true;
                        btn_cancel_d.Enabled = true;
                        btn_new_d.Enabled = false;
                        btn_del_d.Enabled = false;
                        btn_modi_d.Enabled = false;

                        btn_new.Enabled = false;
                        btn_modi.Enabled = false;
                        btn_del.Enabled = false;
                        btn_Query.Enabled = false;
                    }

                }
                else
                {
                    MessageBox.Show("未选择要修改的明细！");
                    return;
                }
            }
            else//分配 到托盘批次
            {
                if (dvg_move_out2.Rows.Count > 0)
                {
                    #region 判断是否审核
                    DataRow[] dr_check = ds_move.Tables[0].Select("move_trans = '" + cbx_transaction_type.Text.Trim() + "'");
                    if (dr_check.Length > 0)
                    {
                        if (dr_check[0]["content2"].ToString().Trim() == "1")//需要审核
                        {
                            DataSet ds_con;
                            string str_sql = "select standby_4 From " + main.g_space + ".inv_move_header  where inv_org='" + main.g_org + "' and consignor='" + cbx_h_consignor.Text.Trim() + "' and move_no='" + tb_h_move_no.Text.Trim() + "'";
                            try
                            {
                                if (main.dbtype == "SQL")
                                {
                                    ds_con = main.dbservice.Sql_exec_selectsql(str_sql);
                                }
                                else
                                {
                                    ds_con = main.dbservice.oracle_exec_selectsql(str_sql);
                                }

                                if (ds_con.Tables[0].Rows.Count > 0)
                                {
                                    if (ds_con.Tables[0].Rows[0]["standby_4"].ToString().Trim() == "1")
                                    {
                                        MessageBox.Show("当前单据已经审核，不能在修改");
                                        return;
                                    }
                                }
                            }
                            catch (System.Exception ee)
                            {
                                MessageBox.Show(ee.ToString());
                                return;
                            }
                        }
                    #endregion
                        dvg_move_out2.ReadOnly = false;
                        for (int i = 0; i < dvg_move_out2.Rows.Count; i++)
                        {
                            dvg_move_out2.Rows[i].Cells["move_line_no2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["moveout_warehouse2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["moveout_location2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["sku2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["sku_name2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["move_qty_s2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["stock_qty_m2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["stock_qty_s2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["move_cubage2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["move_gross_weight2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["move_net_weight2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["cubage2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["gross_weight2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["net_weight2"].ReadOnly = true;
                            dvg_move_out2.Rows[i].Cells["move_qty_m2"].ReadOnly = false;
                            dvg_move_out2.Rows[i].Cells["movein_warehouse2"].ReadOnly = false;
                            dvg_move_out2.Rows[i].Cells["movein_location2"].ReadOnly = false;
                        }
                        btn_save_d.Enabled = true;
                        btn_cancel_d.Enabled = true;
                        btn_new_d.Enabled = false;
                        btn_del_d.Enabled = false;
                        btn_modi_d.Enabled = false;

                        btn_new.Enabled = false;
                        btn_modi.Enabled = false;
                        btn_del.Enabled = false;
                        btn_Query.Enabled = false;
                    }
                }
                else
                {
                    MessageBox.Show("未选择要修改的明细！");
                    return;
                }
            }
        }
        //判断库存的库位的托盘数量
        private void Judge()
        {
            //DataSet ds_str = new DataSet();
            //string str = "";
            //str = "select leftcount  from " + main.g_space + ".VIEW_SQL_PL_LOC where inv_org = '" + main.g_org + "' and location_code='" + tb_movein_location.Text.Trim() + "'";
            //if (main.dbtype == "SQL")
            //{
            //    ds_str = main.dbservice.Sql_exec_selectsql(str);
            //}
            //else
            //{
            //    ds_str = main.dbservice.oracle_exec_selectsql(str);
            //}
            //if (ds_str.Tables[0].Rows.Count > 0)
            //{
            //    if (Convert.ToDecimal(ds_str.Tables[0].Rows[0][0]) < Convert.ToDecimal(tb_move_qty_m.Text.Trim()))//判断库位是否可用
            //    {
            //        MessageBox.Show(main.g_class.comm_getchangestring("" + tb_movein_location.Text.Trim() + "Location code lack of capacity can not be moved sku!", main.g_info_dataset) + "!");
            //        coint_d = 0;
            //        return;
            //    }
            //}
        }
        private void btn_save_d_Click(object sender, EventArgs e)
        {
            if (str_type == "0")
            {
                #region 保持原来的操作方式
                if (dvg_move_out.Rows.Count > 0)
                {
                    DataSet ds_save = new DataSet();
                    DataTable dt_sa = new DataTable();

                    dt_sa.Columns.Add("sp_lineon");
                    dt_sa.Columns.Add("sp_warehousein");
                    dt_sa.Columns.Add("sp_pallet");
                    dt_sa.Columns.Add("sp_batch");
                    dt_sa.Columns.Add("sp_sku");
                    dt_sa.Columns.Add("sp_use_qty");
                    dt_sa.Columns.Add("sp_use_qty_s");
                    dt_sa.Columns.Add("sp_outloc");
                    dt_sa.Columns.Add("sp_inloc");
                    for (int i = 0; i < dvg_move_out.Rows.Count; i++)
                    {
                        for (int j = 0; j < ds_copy.Tables[0].Rows.Count; j++)
                        {
                            if (dvg_move_out.Rows[i].Cells["inv_org"].Value.ToString().Trim() == ds_copy.Tables[0].Rows[j]["inv_org"].ToString().Trim() && dvg_move_out.Rows[i].Cells["consignor_d"].Value.ToString().Trim() == ds_copy.Tables[0].Rows[j]["consignor"].ToString().Trim() && dvg_move_out.Rows[i].Cells["move_no_d"].Value.ToString().Trim() == ds_copy.Tables[0].Rows[j]["move_no"].ToString().Trim() && dvg_move_out.Rows[i].Cells["move_line_no"].Value.ToString().Trim() == ds_copy.Tables[0].Rows[j]["move_line_no"].ToString().Trim())
                            {
                                if (dvg_move_out.Rows[i].Cells["movein_warehouse"].Value.ToString().Trim() != ds_copy.Tables[0].Rows[j]["movein_warehouse"].ToString().Trim() || dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim() != ds_copy.Tables[0].Rows[j]["movein_location"].ToString().Trim() || dvg_move_out.Rows[i].Cells["move_qty_m"].Value.ToString().Trim() != ds_copy.Tables[0].Rows[j]["move_qty_m"].ToString().Trim())
                                {
                                    if (str_warehouse.Trim() == "0")//移库是否不可以不同仓
                                    {
                                        if (dvg_move_out.Rows[i].Cells["moveout_warehouse"].Value.ToString().Trim() != dvg_move_out.Rows[i].Cells["movein_warehouse"].Value.ToString().Trim())
                                        {
                                            MessageBox.Show("移库不可以不同仓!");
                                            return;
                                        }
                                    }
                                    #region  判断库位是否合法

                                    string str_customer = "", str_sku = "", str_outloc = "", str_inloc = "", str_pack = "";
                                    decimal d_qty = 0;
                                    // 库位是否为空
                                    if (dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim() == "")
                                    {
                                        MessageBox.Show("移入库位不能为空!");
                                        for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                        {
                                            dvg_move_out.Rows[j].Selected = false;
                                        }
                                        dvg_move_out.Rows[i].Selected = true;
                                        return;
                                    }
                                    else
                                    {
                                        str_customer = cbx_h_consignor.Text.Trim();
                                        str_sku = dvg_move_out.Rows[i].Cells["sku"].Value.ToString().Trim();
                                        str_outloc = dvg_move_out.Rows[i].Cells["moveout_location"].Value.ToString().Trim();
                                        str_inloc = dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim();
                                        str_pack = dvg_move_out.Rows[i].Cells["pack_code"].Value.ToString().Trim();
                                        d_qty = Math.Round(System.Convert.ToDecimal(dvg_move_out.Rows[i].Cells["move_qty_m"].Value.ToString().Trim()), 4);

                                        //判断库位是否合法
                                        DataSet ds_loc;
                                        string str_sql2 = "select c.warehouse_name,a.location_code,case a.location_flag when '0' then '正常' when '1' then '退货' when '2' then '坏品' when '3' then '寄售库位' else '' end location_flag,case a.kind_flag when '0' then '正常' when '1' then 'A位' when '2' then '堆放区' else '' end kind_flag ,case a.standby_flag1 when '0' then '非保税库位' when '1' then '保税库位' else '' end standby_flag1,case a.lock_flag when '0' then '正常' when '1' then '锁定' else '' end lock_flag" +
                                                        " from " + main.g_space + ".mst_location a," + main.g_space + ".mst_area b," + main.g_space + ".mst_warehouse c where c.warehouse=b.warehouse " +
                                                        " and b.area_code=a.area_code and c.inv_org='" + main.g_org.Trim() + "' and a.inv_org='" + main.g_org.Trim() + "'  and b.inv_org='" + main.g_org.Trim() + "' and  c.warehouse='" + dvg_move_out.Rows[i].Cells["movein_warehouse"].Value.ToString().Trim() + "' and a.location_code='" + dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim() + "'";

                                        try
                                        {
                                            if (main.dbtype == "SQL")
                                                ds_loc = main.dbservice.Sql_exec_selectsql(str_sql2);
                                            else
                                                ds_loc = main.dbservice.oracle_exec_selectsql(str_sql2);

                                            if (ds_loc.Tables[0].Rows.Count < 1)
                                            {
                                                MessageBox.Show("输入的移入库位不存在");
                                                for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                                {
                                                    dvg_move_out.Rows[j].Selected = false;
                                                }
                                                dvg_move_out.Rows[i].Selected = true;
                                                return;
                                            }
                                        }
                                        catch (System.Exception ee)
                                        {
                                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                                            return;
                                        }
                                        if (dvg_move_out.Rows[i].Cells["moveout_location"].Value.ToString().Trim() != dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim())
                                        {
                                            //如果移入库位是坏品,则不需要判断
                                            string str_lssql, str_loc = "";
                                            str_loc = dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim();
                                            if (main.dbtype == "SQL")
                                            {
                                                str_lssql = "select isnull(max(location_flag),'0') from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and location_code = '" + str_loc + "'";
                                                str_lssql = main.dbservice.Sql_exec_selectstring(str_lssql);
                                            }
                                            else
                                            {
                                                str_lssql = "select nvl(max(location_flag),'0') from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and location_code = '" + str_loc + "'";
                                                str_lssql = main.dbservice.oracle_exec_selectstring(str_lssql);
                                            }
                                            if (str_lssql.Trim() == "0") //说明是正常库位,需要判断
                                            {
                                                str_loc = "";
                                                try
                                                {
                                                    if (main.dbtype == "SQL")
                                                    {
                                                        str_loc = main.dbservice.Sql_exec_proc_moveloc(main.g_org, str_customer, str_sku, str_outloc, str_inloc, d_qty, str_pack);
                                                    }
                                                    else
                                                    {
                                                        str_loc = main.dbservice.oracle_exec_proc_moveloc(main.g_org, str_customer, str_sku, str_outloc, str_inloc, d_qty, str_pack);
                                                    }

                                                }
                                                catch (System.Exception ee)
                                                {
                                                    MessageBox.Show(ee.ToString());
                                                    f_disply_detail(cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim());
                                                    return;
                                                }
                                                if (str_loc.Trim().ToUpper() != "KNOWN")
                                                {
                                                    MessageBox.Show(str_loc.Trim());
                                                    f_disply_detail(cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim());
                                                    return;
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                    #region  判断商品是否是托盘管理，托盘管理要否可以混放商品和批次
                                    //判断商品是否是托盘管理，托盘管理要否可以混放商品和批次
                                    if (dvg_move_out.Rows[i].Cells["pallet_flag"].Value.ToString().Trim() == "1")
                                    {
                                        //DataSet ds_min;
                                        //if (dvg_move_out.Rows[i].Cells["mix_sku"].Value.ToString().Trim() == "0")//不允许混放产品
                                        //{
                                        //    string s_sql = "select a.*,b.mix_sku,b.mix_lotno from " + main.g_space + ".inv_sku_location a," + main.g_space + ".mst_sku b where  a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku and a.inv_org ='" + main.g_org + "' and a.consignor ='" + cb_consignor.Text.Trim() + "' and a.location_code ='" + dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim() + "'" +
                                        //                    " and (stock_qty_m + movein_qty_m + replenishin_qty_m - moveout_qty_m -replenishout_qty_m - freeze_qty_m " +
                                        //                    " - allocate_qty_m) >0 and a.sku <> '" + dvg_move_out.Rows[i].Cells["sku"].Value.ToString().Trim() + "'";

                                        //    try
                                        //    {
                                        //        if (main.dbtype == "SQL")
                                        //            ds_min = main.dbservice.Sql_exec_selectsql(s_sql);
                                        //        else
                                        //            ds_min = main.dbservice.oracle_exec_selectsql(s_sql);
                                        //        if (ds_min.Tables[0].Rows.Count > 0)
                                        //        {
                                        //            MessageBox.Show("当前商品不能混放，移入库位上已经有商品。");
                                        //            for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                        //            {
                                        //                dvg_move_out.Rows[j].Selected = false;
                                        //            }
                                        //            dvg_move_out.Rows[i].Selected = true;
                                        //            return;
                                        //        }
                                        //    }
                                        //    catch (System.Exception ee)
                                        //    {
                                        //        MessageBox.Show(ee.Message);
                                        //        for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                        //        {
                                        //            dvg_move_out.Rows[j].Selected = false;
                                        //        }
                                        //        dvg_move_out.Rows[i].Selected = true;
                                        //        return;
                                        //    }
                                        //}
                                        //if (dvg_move_out.Rows[i].Cells["mix_lotno"].Value.ToString().Trim() == "0")//不允许混放批次
                                        //{
                                        //    string s_sql = "select a.*,b.mix_sku,b.mix_lotno from " + main.g_space + ".inv_sku_location a," + main.g_space + ".mst_sku b where  a.inv_org=b.inv_org and a.consignor=b.consignor and a.sku=b.sku and a.inv_org ='" + main.g_org + "' and a.consignor ='" + cb_consignor.Text.Trim() + "' and a.location_code ='" + dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim() + "'" +
                                        //                   " and (stock_qty_m + movein_qty_m + replenishin_qty_m - moveout_qty_m -replenishout_qty_m - freeze_qty_m " +
                                        //                   " - allocate_qty_m) >0 and a.sku = '" + dvg_move_out.Rows[i].Cells["sku"].Value.ToString().Trim() + "'";

                                        //    try
                                        //    {
                                        //        if (main.dbtype == "SQL")
                                        //            ds_min = main.dbservice.Sql_exec_selectsql(s_sql);
                                        //        else
                                        //            ds_min = main.dbservice.oracle_exec_selectsql(s_sql);
                                        //        if (ds_min.Tables[0].Rows.Count > 0)
                                        //        {
                                        //            MessageBox.Show("当前商品不能混放批次，移入库位上已经有这个商品。");
                                        //            for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                        //            {
                                        //                dvg_move_out.Rows[j].Selected = false;
                                        //            }
                                        //            dvg_move_out.Rows[i].Selected = true;
                                        //            return;
                                        //        }
                                        //    }
                                        //    catch (System.Exception ee)
                                        //    {
                                        //        MessageBox.Show(ee.Message);
                                        //        for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                        //        {
                                        //            dvg_move_out.Rows[j].Selected = false;
                                        //        }
                                        //        dvg_move_out.Rows[i].Selected = true;
                                        //        return;
                                        //    }
                                        //}
                                    }
                                    else //非托盘的判断是否有不同包装的
                                    {
                                        string str_pa = "select *From " + main.g_space + ".inv_sku_location where inv_org='" + main.g_org + "' and consignor='" + cb_consignor.Text.Trim() + "' and sku='" + dvg_move_out.Rows[i].Cells["sku"].Value.ToString().Trim() + "' and location_code='" + dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim() + "' and pack_code<> '" + dvg_move_out.Rows[i].Cells["pack_code"].Value.ToString().Trim() + "' and stock_qty_m>0";
                                        DataSet ds_pack;
                                        //判断库位中如果有同样商品不同包装的，不能移入
                                        try
                                        {
                                            if (main.dbtype == "SQL")
                                                ds_pack = main.dbservice.Sql_exec_selectsql(str_pa);
                                            else
                                                ds_pack = main.dbservice.oracle_exec_selectsql(str_pa);
                                            if (ds_pack.Tables[0].Rows.Count > 0)
                                            {
                                                MessageBox.Show("当前商品在移入库位上已经有不同包装，不能移入。");
                                                for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                                {
                                                    dvg_move_out.Rows[j].Selected = false;
                                                }
                                                dvg_move_out.Rows[i].Selected = true;
                                                return;
                                            }
                                        }
                                        catch (System.Exception ee)
                                        {
                                            MessageBox.Show(ee.Message);
                                            for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                            {
                                                dvg_move_out.Rows[j].Selected = false;
                                            }
                                            dvg_move_out.Rows[i].Selected = true;
                                            return;
                                        }
                                        str_pa = "select * From " + main.g_space + ".asn_putaway where inv_org='" + main.g_org + "' and consignor='" + cb_consignor.Text.Trim() + "' and sku='" + dvg_move_out.Rows[i].Cells["sku"].Value.ToString().Trim() + "' and suggest_location='" + dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim() + "' and pack_code<> '" + dvg_move_out.Rows[i].Cells["pack_code"].Value.ToString().Trim() + "' and putaway_status='0'";
                                        try
                                        {
                                            if (main.dbtype == "SQL")
                                                ds_pack = main.dbservice.Sql_exec_selectsql(str_pa);
                                            else
                                                ds_pack = main.dbservice.oracle_exec_selectsql(str_pa);
                                            if (ds_pack.Tables[0].Rows.Count > 0)
                                            {
                                                MessageBox.Show("当前商品在要移入库位已经有数据在上架单中有不同包装的待上架。");
                                                for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                                {
                                                    dvg_move_out.Rows[j].Selected = false;
                                                }
                                                dvg_move_out.Rows[i].Selected = true;
                                                return;
                                            }
                                        }
                                        catch (System.Exception ee)
                                        {
                                            MessageBox.Show(ee.Message);
                                            for (int k = 0; k < dvg_move_out.Rows.Count; k++)
                                            {
                                                dvg_move_out.Rows[j].Selected = false;
                                            }
                                            dvg_move_out.Rows[i].Selected = true;
                                            return;
                                        }

                                    }
                                    #endregion

                                    #region 修改

                                    DataRow dr = dt_sa.NewRow();
                                    dr["sp_lineon"] = dvg_move_out.Rows[i].Cells["move_line_no"].Value.ToString().Trim();
                                    dr["sp_warehousein"] = dvg_move_out.Rows[i].Cells["movein_warehouse"].Value.ToString().Trim();
                                    dr["sp_pallet"] = "";
                                    dr["sp_batch"] = "";
                                    dr["sp_sku"] = dvg_move_out.Rows[i].Cells["sku"].Value.ToString().Trim();
                                    dr["sp_use_qty"] = dvg_move_out.Rows[i].Cells["move_qty_m"].Value.ToString().Trim();
                                    dr["sp_use_qty_s"] = dvg_move_out.Rows[i].Cells["move_qty_s"].Value.ToString().Trim();
                                    dr["sp_outloc"] = dvg_move_out.Rows[i].Cells["moveout_location"].Value.ToString().Trim();
                                    dr["sp_inloc"] = dvg_move_out.Rows[i].Cells["movein_location"].Value.ToString().Trim();
                                    dt_sa.Rows.Add(dr);

                                    #endregion
                                }
                            }

                        }
                    }
                    try
                    {
                        if (dt_sa.Rows.Count > 0)
                        {
                            string str_message = "";
                            ds_save.Tables.Add(dt_sa);
                            if (main.dbtype == "SQL")
                            {
                                str_message = main.dbservice.Sql_exec_proc_movemodify_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_save, main.g_user);
                            }
                            else
                            {
                                str_message = main.dbservice.oracle_exec_proc_movemodify_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_save, main.g_user);
                            }
                            if (str_message.Trim() != "")
                            {
                                MessageBox.Show("保存失败" + str_message);
                                return;
                            }
                            f_disply_detail(cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim());
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to save!", main.g_info_dataset) + "!" + ee.ToString());
                        Cursor.Current = Cursors.Default;
                        return;
                    }

                }

                #endregion
            }
            else//分配到托盘批次
            {
                #region 分配到托盘批次
                if (dvg_move_out2.Rows.Count > 0)
                {
                    DataSet ds_save = new DataSet();
                    DataTable dt_sa = new DataTable();

                    dt_sa.Columns.Add("sp_lineon");
                    dt_sa.Columns.Add("sp_warehousein");
                    dt_sa.Columns.Add("sp_pallet");
                    dt_sa.Columns.Add("sp_batch");
                    dt_sa.Columns.Add("sp_sku");
                    dt_sa.Columns.Add("sp_use_qty");
                    dt_sa.Columns.Add("sp_use_qty_s");
                    dt_sa.Columns.Add("sp_outloc");
                    dt_sa.Columns.Add("sp_inloc");
                    for (int i = 0; i < dvg_move_out2.Rows.Count; i++)
                    {
                        for (int j = 0; j < ds_copy.Tables[0].Rows.Count; j++)
                        {
                            if (dvg_move_out2.Rows[i].Cells["inv_org2"].Value.ToString().Trim() == ds_copy.Tables[0].Rows[j]["inv_org"].ToString().Trim() && dvg_move_out2.Rows[i].Cells["consignor2"].Value.ToString().Trim() == ds_copy.Tables[0].Rows[j]["consignor"].ToString().Trim() && dvg_move_out2.Rows[i].Cells["move_no2"].Value.ToString().Trim() == ds_copy.Tables[0].Rows[j]["move_no"].ToString().Trim() && dvg_move_out2.Rows[i].Cells["move_line_no2"].Value.ToString().Trim() == ds_copy.Tables[0].Rows[j]["move_line_no"].ToString().Trim())
                            {
                                if (dvg_move_out2.Rows[i].Cells["movein_warehouse2"].Value.ToString().Trim() != ds_copy.Tables[0].Rows[j]["movein_warehouse"].ToString().Trim() || dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim() != ds_copy.Tables[0].Rows[j]["movein_location"].ToString().Trim() || dvg_move_out2.Rows[i].Cells["move_qty_m2"].Value.ToString().Trim() != ds_copy.Tables[0].Rows[j]["move_qty_m"].ToString().Trim())
                                {
                                    if (str_warehouse.Trim() == "0")//移库是否不可以不同仓
                                    {
                                        if (dvg_move_out2.Rows[i].Cells["moveout_warehouse2"].Value.ToString().Trim() != dvg_move_out2.Rows[i].Cells["movein_warehouse2"].Value.ToString().Trim())
                                        {
                                            MessageBox.Show("移库不可以不同仓!");
                                            return;
                                        }
                                    }
                                    #region  判断库位是否合法

                                    string str_customer = "", str_sku = "", str_outloc = "", str_inloc = "", str_pack = "";
                                    decimal d_qty = 0;
                                    // 库位是否为空
                                    if (dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim() == "")
                                    {
                                        MessageBox.Show("移入库位不能为空!");
                                        for (int k = 0; k < dvg_move_out2.Rows.Count; k++)
                                        {
                                            dvg_move_out2.Rows[j].Selected = false;
                                        }
                                        dvg_move_out2.Rows[i].Selected = true;
                                        return;
                                    }
                                    else
                                    {
                                        str_customer = cbx_h_consignor.Text.Trim();
                                        str_sku = dvg_move_out2.Rows[i].Cells["sku2"].Value.ToString().Trim();
                                        str_outloc = dvg_move_out2.Rows[i].Cells["moveout_location2"].Value.ToString().Trim();
                                        str_inloc = dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim();
                                        str_pack = dvg_move_out2.Rows[i].Cells["pack_code2"].Value.ToString().Trim();
                                        d_qty = Math.Round(System.Convert.ToDecimal(dvg_move_out2.Rows[i].Cells["move_qty_m2"].Value.ToString().Trim()), 4);

                                        //判断库位是否合法
                                        DataSet ds_loc;
                                        string str_sql2 = "select c.warehouse_name,a.location_code,case a.location_flag when '0' then '正常' when '1' then '退货' when '2' then '坏品' when '3' then '寄售库位' else '' end location_flag,case a.kind_flag when '0' then '正常' when '1' then 'A位' when '2' then '堆放区' else '' end kind_flag ,case a.standby_flag1 when '0' then '非保税库位' when '1' then '保税库位' else '' end standby_flag1,case a.lock_flag when '0' then '正常' when '1' then '锁定' else '' end lock_flag" +
                                                        " from " + main.g_space + ".mst_location a," + main.g_space + ".mst_area b," + main.g_space + ".mst_warehouse c where c.warehouse=b.warehouse " +
                                                        " and b.area_code=a.area_code and c.inv_org='" + main.g_org.Trim() + "' and a.inv_org='" + main.g_org.Trim() + "'  and b.inv_org='" + main.g_org.Trim() + "' and  c.warehouse='" + dvg_move_out2.Rows[i].Cells["movein_warehouse2"].Value.ToString().Trim() + "' and a.location_code='" + dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim() + "'";

                                        try
                                        {
                                            if (main.dbtype == "SQL")
                                                ds_loc = main.dbservice.Sql_exec_selectsql(str_sql2);
                                            else
                                                ds_loc = main.dbservice.oracle_exec_selectsql(str_sql2);

                                            if (ds_loc.Tables[0].Rows.Count < 1)
                                            {
                                                MessageBox.Show("输入的移入库位不存在");
                                                for (int k = 0; k < dvg_move_out2.Rows.Count; k++)
                                                {
                                                    dvg_move_out2.Rows[j].Selected = false;
                                                }
                                                dvg_move_out2.Rows[i].Selected = true;
                                                return;
                                            }
                                        }
                                        catch (System.Exception ee)
                                        {
                                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());
                                            return;
                                        }
                                        if (dvg_move_out2.Rows[i].Cells["moveout_location2"].Value.ToString().Trim() != dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim())
                                        {
                                            //如果移入库位是坏品,则不需要判断
                                            string str_lssql, str_loc = "";
                                            str_loc = dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim();
                                            if (main.dbtype == "SQL")
                                            {
                                                str_lssql = "select isnull(max(location_flag),'0') from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and location_code = '" + str_loc + "'";
                                                str_lssql = main.dbservice.Sql_exec_selectstring(str_lssql);
                                            }
                                            else
                                            {
                                                str_lssql = "select nvl(max(location_flag),'0') from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and location_code = '" + str_loc + "'";
                                                str_lssql = main.dbservice.oracle_exec_selectstring(str_lssql);
                                            }
                                            if (str_lssql.Trim() == "0") //说明是正常库位,需要判断
                                            {
                                                str_loc = "";
                                                try
                                                {
                                                    if (main.dbtype == "SQL")
                                                    {
                                                        str_loc = main.dbservice.Sql_exec_proc_moveloc(main.g_org, str_customer, str_sku, str_outloc, str_inloc, d_qty, str_pack);
                                                    }
                                                    else
                                                    {
                                                        str_loc = main.dbservice.oracle_exec_proc_moveloc(main.g_org, str_customer, str_sku, str_outloc, str_inloc, d_qty, str_pack);
                                                    }

                                                }
                                                catch (System.Exception ee)
                                                {
                                                    MessageBox.Show(ee.ToString());
                                                    return;
                                                }
                                                if (str_loc.Trim().ToUpper() != "KNOWN")
                                                {
                                                    MessageBox.Show(str_loc.Trim());
                                                    return;
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                    #region  判断商品是否是托盘管理，托盘管理要否可以混放商品和批次
                                    //判断商品是否是托盘管理，托盘管理要否可以混放商品和批次
                                    if (dvg_move_out2.Rows[i].Cells["pallet_flag2"].Value.ToString().Trim() == "1")
                                    {
                                    }
                                    else //非托盘的判断是否有不同包装的
                                    {
                                        string str_pa = "select *From " + main.g_space + ".inv_sku_location where inv_org='" + main.g_org + "' and consignor='" + cb_consignor.Text.Trim() + "' and sku='" + dvg_move_out2.Rows[i].Cells["sku2"].Value.ToString().Trim() + "' and location_code='" + dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim() + "' and pack_code<> '" + dvg_move_out2.Rows[i].Cells["pack_code2"].Value.ToString().Trim() + "' and stock_qty_m>0";
                                        DataSet ds_pack;
                                        //判断库位中如果有同样商品不同包装的，不能移入
                                        try
                                        {
                                            if (main.dbtype == "SQL")
                                                ds_pack = main.dbservice.Sql_exec_selectsql(str_pa);
                                            else
                                                ds_pack = main.dbservice.oracle_exec_selectsql(str_pa);
                                            if (ds_pack.Tables[0].Rows.Count > 0)
                                            {
                                                MessageBox.Show("当前商品在移入库位上已经有不同包装，不能移入。");
                                                for (int k = 0; k < dvg_move_out2.Rows.Count; k++)
                                                {
                                                    dvg_move_out2.Rows[j].Selected = false;
                                                }
                                                dvg_move_out2.Rows[i].Selected = true;
                                                return;
                                            }
                                        }
                                        catch (System.Exception ee)
                                        {
                                            MessageBox.Show(ee.Message);
                                            for (int k = 0; k < dvg_move_out2.Rows.Count; k++)
                                            {
                                                dvg_move_out2.Rows[j].Selected = false;
                                            }
                                            dvg_move_out2.Rows[i].Selected = true;
                                            return;
                                        }
                                        str_pa = "select * From " + main.g_space + ".asn_putaway where inv_org='" + main.g_org + "' and consignor='" + cb_consignor.Text.Trim() + "' and sku='" + dvg_move_out2.Rows[i].Cells["sku2"].Value.ToString().Trim() + "' and suggest_location='" + dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim() + "' and pack_code<> '" + dvg_move_out2.Rows[i].Cells["pack_code2"].Value.ToString().Trim() + "' and putaway_status='0'";
                                        try
                                        {
                                            if (main.dbtype == "SQL")
                                                ds_pack = main.dbservice.Sql_exec_selectsql(str_pa);
                                            else
                                                ds_pack = main.dbservice.oracle_exec_selectsql(str_pa);
                                            if (ds_pack.Tables[0].Rows.Count > 0)
                                            {
                                                MessageBox.Show("当前商品在要移入库位已经有数据在上架单中有不同包装的待上架。");
                                                for (int k = 0; k < dvg_move_out2.Rows.Count; k++)
                                                {
                                                    dvg_move_out2.Rows[j].Selected = false;
                                                }
                                                dvg_move_out2.Rows[i].Selected = true;
                                                return;
                                            }
                                        }
                                        catch (System.Exception ee)
                                        {
                                            MessageBox.Show(ee.Message);
                                            for (int k = 0; k < dvg_move_out2.Rows.Count; k++)
                                            {
                                                dvg_move_out2.Rows[j].Selected = false;
                                            }
                                            dvg_move_out2.Rows[i].Selected = true;
                                            return;
                                        }

                                    }
                                    #endregion

                                    #region 修改

                                    DataRow dr = dt_sa.NewRow();
                                    dr["sp_lineon"] = dvg_move_out2.Rows[i].Cells["move_line_no2"].Value.ToString().Trim();
                                    dr["sp_warehousein"] = dvg_move_out2.Rows[i].Cells["movein_warehouse2"].Value.ToString().Trim();
                                    dr["sp_pallet"] = dvg_move_out2.Rows[i].Cells["moveout_pallet2"].Value.ToString().Trim();
                                    dr["sp_batch"] = dvg_move_out2.Rows[i].Cells["batchno2"].Value.ToString().Trim();
                                    dr["sp_sku"] = dvg_move_out2.Rows[i].Cells["sku2"].Value.ToString().Trim();
                                    dr["sp_use_qty"] = dvg_move_out2.Rows[i].Cells["move_qty_m2"].Value.ToString().Trim();
                                    dr["sp_use_qty_s"] = dvg_move_out2.Rows[i].Cells["move_qty_s2"].Value.ToString().Trim();
                                    dr["sp_outloc"] = dvg_move_out2.Rows[i].Cells["moveout_location2"].Value.ToString().Trim();
                                    dr["sp_inloc"] = dvg_move_out2.Rows[i].Cells["movein_location2"].Value.ToString().Trim();
                                    dt_sa.Rows.Add(dr);

                                    #endregion
                                }
                            }

                        }
                    }
                    try
                    {
                        if (dt_sa.Rows.Count > 0)
                        {
                            string str_message = "";
                            ds_save.Tables.Add(dt_sa);
                            if (main.dbtype == "SQL")
                            {
                                str_message = main.dbservice.Sql_exec_proc_movemodify_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_save, main.g_user);
                            }
                            else
                            {
                                str_message = main.dbservice.oracle_exec_proc_movemodify_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_save, main.g_user);
                            }
                            if (str_message.Trim() != "")
                            {
                                MessageBox.Show("保存失败" + str_message);
                                return;
                            }
                            f_disply_detail(cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim());
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to save!", main.g_info_dataset) + "!" + ee.ToString());
                        Cursor.Current = Cursors.Default;
                        return;
                    }

                }

                #endregion
            }
            btn_new_d.Enabled = true; ;
            btn_del_d.Enabled = true;
            btn_modi_d.Enabled = true;
            btn_save_d.Enabled = false;
            btn_cancel_d.Enabled = false;

            btn_new.Enabled = true;
            btn_modi.Enabled = true;
            btn_del.Enabled = true;
            btn_Query.Enabled = true;

            dvg_move_out.ReadOnly = true;
        }

        private void rbtn_all_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < this.dvg_move_out.Rows.Count; i++)
            {
                this.dvg_move_out.Rows[i].Cells[0].Value = true;
            }
        }

        private void rbtn_notall_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < this.dvg_move_out.Rows.Count; i++)
            {
                this.dvg_move_out.Rows[i].Cells[0].Value = false;
            }
        }

        //private void btn_Confirm_d_Click(object sender, EventArgs e)
        //{
        //    string row_no = "";
        //    if (this.dvg_move_out.Rows.Count > 0)
        //    {
        //        for (int i = 0; i < this.dvg_move_out.Rows.Count; i++)
        //        {
        //            if (this.dvg_move_out.Rows[i].Cells[0].EditedFormattedValue.ToString().Trim().ToLower()=="true")
        //            {
        //                //存储过程WMS.SP_SQL_MOME_CONFIRM
        //            }
        //        }
        //    }
        //}


        private void btn_del_d_Click(object sender, EventArgs e)
        {
            if (str_type == "0")//保持原来不变
            {
                if (dvg_move_out.Rows.Count == 0)
                {

                    MessageBox.Show("未选择要删除的明细！");
                    return;
                }
                if (dvg_move_out.Rows.Count > 0)
                {
                    if (dvg_move_out.CurrentRow == null)
                    {

                        MessageBox.Show("未选择要删除的明细！");
                        return;
                    }
                    #region 判断是否审核
                    DataRow[] dr_check = ds_move.Tables[0].Select("move_trans = '" + cbx_transaction_type.Text.Trim() + "'");
                    if (dr_check.Length > 0)
                    {
                        if (dr_check[0]["content2"].ToString().Trim() == "1")//需要审核
                        {
                            DataSet ds_con;
                            string str_sql = "select standby_4 From " + main.g_space + ".inv_move_header  where inv_org='" + main.g_org + "' and consignor='" + cbx_h_consignor.Text.Trim() + "' and move_no='" + tb_h_move_no.Text.Trim() + "'";
                            try
                            {
                                if (main.dbtype == "SQL")
                                {
                                    ds_con = main.dbservice.Sql_exec_selectsql(str_sql);
                                }
                                else
                                {
                                    ds_con = main.dbservice.oracle_exec_selectsql(str_sql);
                                }

                                if (ds_con.Tables[0].Rows.Count > 0)
                                {
                                    if (ds_con.Tables[0].Rows[0]["standby_4"].ToString().Trim() == "1")
                                    {
                                        MessageBox.Show("当前单据已经审核，不能在修改");
                                        return;
                                    }
                                }
                            }
                            catch (System.Exception ee)
                            {
                                MessageBox.Show(ee.ToString());
                                return;
                            }
                        }
                    #endregion
                        if (MessageBox.Show("是否确认删除选择项?", "Information", MessageBoxButtons.YesNo) == DialogResult.No)
                        {
                            return;
                        }
                        DataTable dt_delete = new DataTable();
                        DataSet ds_del = new DataSet();
                        dt_delete.Columns.Add("sp_lineon");
                        dt_delete.Columns.Add("sp_pallet");
                        dt_delete.Columns.Add("sp_in_pallet");
                        dt_delete.Columns.Add("sp_batch");
                        dt_delete.Columns.Add("sp_sku");
                        dt_delete.Columns.Add("sp_use_qty");
                        dt_delete.Columns.Add("sp_use_qty_s");
                        dt_delete.Columns.Add("sp_outloc");
                        dt_delete.Columns.Add("sp_inloc");

                        for (int i = 0; i < dvg_move_out.SelectedRows.Count; i++)
                        {
                            DataRow dr = dt_delete.NewRow();
                            dr["sp_lineon"] = dvg_move_out.SelectedRows[i].Cells["move_line_no"].Value.ToString().Trim();
                            dr["sp_pallet"] = "";
                            dr["sp_in_pallet"] = "";
                            dr["sp_batch"] = "";
                            dr["sp_sku"] = dvg_move_out.SelectedRows[i].Cells["sku"].Value.ToString().Trim();
                            dr["sp_use_qty"] = dvg_move_out.SelectedRows[i].Cells["move_qty_m"].Value.ToString().Trim();
                            dr["sp_use_qty_s"] = dvg_move_out.SelectedRows[i].Cells["move_qty_s"].Value.ToString().Trim();
                            dr["sp_outloc"] = dvg_move_out.SelectedRows[i].Cells["moveout_location"].Value.ToString().Trim();
                            dr["sp_inloc"] = dvg_move_out.SelectedRows[i].Cells["movein_location"].Value.ToString().Trim();
                            dt_delete.Rows.Add(dr);
                        }
                        try
                        {
                            if (dt_delete.Rows.Count > 0)
                            {
                                ds_del.Tables.Add(dt_delete);
                                string str_message = "";
                                if (main.dbtype == "SQL")
                                {
                                    str_message = main.dbservice.Sql_exec_proc_movedel_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_del, main.g_user);
                                }
                                else
                                {
                                    str_message = main.dbservice.oracle_exec_proc_movedel_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_del, main.g_user);
                                }
                                if (str_message.Trim() != "")
                                {
                                    MessageBox.Show("删除失败" + str_message);
                                    return;
                                }
                                f_disply_detail(cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim());
                            }

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save !", main.g_info_dataset) + "!" + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
            }
            else// 分配 到托盘批次
            {
                if (dvg_move_out2.Rows.Count == 0)
                {

                    MessageBox.Show("未选择要删除的明细！");
                    return;
                }
                if (dvg_move_out2.Rows.Count > 0)
                {
                    if (dvg_move_out2.CurrentRow == null)
                    {
                        MessageBox.Show("未选择要删除的明细！");
                        return;
                    }
                    #region 判断是否审核
                    DataRow[] dr_check = ds_move.Tables[0].Select("move_trans = '" + cbx_transaction_type.Text.Trim() + "'");
                    if (dr_check.Length > 0)
                    {
                        if (dr_check[0]["content2"].ToString().Trim() == "1")//需要审核
                        {
                            DataSet ds_con;
                            string str_sql = "select standby_4 From " + main.g_space + ".inv_move_header  where inv_org='" + main.g_org + "' and consignor='" + cbx_h_consignor.Text.Trim() + "' and move_no='" + tb_h_move_no.Text.Trim() + "'";
                            try
                            {
                                if (main.dbtype == "SQL")
                                {
                                    ds_con = main.dbservice.Sql_exec_selectsql(str_sql);
                                }
                                else
                                {
                                    ds_con = main.dbservice.oracle_exec_selectsql(str_sql);
                                }

                                if (ds_con.Tables[0].Rows.Count > 0)
                                {
                                    if (ds_con.Tables[0].Rows[0]["standby_4"].ToString().Trim() == "1")
                                    {
                                        MessageBox.Show("当前单据已经审核，不能在修改");
                                        return;
                                    }
                                }
                            }
                            catch (System.Exception ee)
                            {
                                MessageBox.Show(ee.ToString());
                                return;
                            }
                        }
                    #endregion
                        if (MessageBox.Show("是否确认删除选择项?", "Information", MessageBoxButtons.YesNo) == DialogResult.No)
                        {
                            return;
                        }
                        DataTable dt_delete = new DataTable();
                        DataSet ds_del = new DataSet();
                        dt_delete.Columns.Add("sp_lineon");
                        dt_delete.Columns.Add("sp_pallet");
                        dt_delete.Columns.Add("sp_in_pallet");
                        dt_delete.Columns.Add("sp_batch");
                        dt_delete.Columns.Add("sp_sku");
                        dt_delete.Columns.Add("sp_use_qty");
                        dt_delete.Columns.Add("sp_use_qty_s");
                        dt_delete.Columns.Add("sp_outloc");
                        dt_delete.Columns.Add("sp_inloc");

                        for (int i = 0; i < dvg_move_out2.SelectedRows.Count; i++)
                        {
                            DataRow dr = dt_delete.NewRow();
                            dr["sp_lineon"] = dvg_move_out2.SelectedRows[i].Cells["move_line_no2"].Value.ToString().Trim();
                            dr["sp_pallet"] = dvg_move_out2.SelectedRows[i].Cells["moveout_pallet2"].Value.ToString().Trim();
                            dr["sp_in_pallet"] = dvg_move_out2.SelectedRows[i].Cells["movein_pallet2"].Value.ToString().Trim();
                            dr["sp_batch"] = dvg_move_out2.SelectedRows[i].Cells["batchno2"].Value.ToString().Trim();
                            dr["sp_sku"] = dvg_move_out2.SelectedRows[i].Cells["sku2"].Value.ToString().Trim();
                            dr["sp_use_qty"] = dvg_move_out2.SelectedRows[i].Cells["move_qty_m2"].Value.ToString().Trim();
                            dr["sp_use_qty_s"] = dvg_move_out2.SelectedRows[i].Cells["move_qty_s2"].Value.ToString().Trim();
                            dr["sp_outloc"] = dvg_move_out2.SelectedRows[i].Cells["moveout_location2"].Value.ToString().Trim();
                            dr["sp_inloc"] = dvg_move_out2.SelectedRows[i].Cells["movein_location2"].Value.ToString().Trim();
                            dt_delete.Rows.Add(dr);
                        }
                        try
                        {
                            if (dt_delete.Rows.Count > 0)
                            {
                                ds_del.Tables.Add(dt_delete);
                                string str_message = "";
                                if (main.dbtype == "SQL")
                                {
                                    str_message = main.dbservice.Sql_exec_proc_movedel_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_del, main.g_user);
                                }
                                else
                                {
                                    str_message = main.dbservice.oracle_exec_proc_movedel_header(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), ds_del, main.g_user);
                                }
                                if (str_message.Trim() != "")
                                {
                                    MessageBox.Show("删除失败" + str_message);
                                    return;
                                }
                                f_disply_detail(cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim());
                            }

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to save !", main.g_info_dataset) + "!" + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                    }
                }
            }
        }



        private void btn_cancel_d_Click(object sender, EventArgs e)
        {
            if (str_type == "0")
            {
                ds_temp = ds_copy.Copy();
                dvg_move_out.DataSource = ds_temp.Tables[0];
                dvg_move_out.ReadOnly = true;
            }
            else
            {
                ds_temp = ds_copy.Copy();
                dvg_move_out2.DataSource = ds_temp.Tables[0];
                dvg_move_out2.ReadOnly = true;
            }
            btn_new_d.Enabled = true; ;
            btn_del_d.Enabled = true;
            btn_modi_d.Enabled = true;
            btn_save_d.Enabled = false;
            btn_cancel_d.Enabled = false;

            btn_new.Enabled = true;
            btn_modi.Enabled = true;
            btn_del.Enabled = true;
            btn_Query.Enabled = true;
        }

        private void dvg_move_SelectionChanged(object sender, EventArgs e)
        {

            str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dvg_move.Rows[dvg_move.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "'and move_no='" + dvg_move.Rows[dvg_move.CurrentRow.Index].Cells["move_no"].Value.ToString().Trim() + "'";
            DataRow[] tr = dsmove_header.Tables[0].Select(str_sql_where);
            if (tr.Length > 0)
            {
                show(tr[0]);
                f_disply_detail(tr[0]["consignor"].ToString().Trim(), tr[0]["move_no"].ToString().Trim());
            }
        }

        private void dvg_move_out_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dvg_move_out.CurrentRow != null)
            {
                if (dvg_move_out.Columns[e.ColumnIndex].Name.ToString().Trim() == "movein_location")
                {
                    if (dvg_move_out.Rows[e.RowIndex].Cells["movein_warehouse"].Value.ToString().Trim() != "")
                    {
                        w_inv003locationlist fr = new w_inv003locationlist(dvg_move_out.Rows[e.RowIndex].Cells["movein_warehouse"].Value.ToString().Trim());
                        fr.ShowDialog();
                        dvg_move_out.Rows[e.RowIndex].Cells["movein_location"].Value = fr.str_location_code.Trim();
                    }
                }
            }
        }

        private void dvg_move_out_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            int row_no;
            if (dvg_move_out.CurrentRow != null)
            {
                row_no = e.RowIndex;
                if (row_no >= 0)
                {
                    if (dvg_move_out.Columns[e.ColumnIndex].Name.ToString().Trim() == "move_qty_m")
                    {
                        try
                        {
                            if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
                            {

                            }
                            else
                            {
                                double dnum = Convert.ToDouble(dvg_move_out.Rows[e.RowIndex].Cells["stock_qty_m"].Value.ToString().Trim());
                                double dnum2 = Convert.ToDouble(e.FormattedValue.ToString());
                                if (dnum2.ToString().Trim().Substring(0, 1) == "-")
                                {
                                    dvg_move_out.Rows[e.RowIndex].ErrorText = "移库数不能为负数";
                                    MessageBox.Show("移库数不能为负数");
                                    e.Cancel = true;
                                }
                                if (dnum2 > dnum)
                                {
                                    dvg_move_out.Rows[e.RowIndex].ErrorText = "移库数大于可用数量";
                                    MessageBox.Show("移库数大于可用数量");
                                    e.Cancel = true;
                                }
                                else //计算重量体积
                                {

                                    dvg_move_out.Rows[row_no].Cells["move_qty_s"].Value = Math.Round(Convert.ToDouble(dvg_move_out.Rows[row_no].Cells["convert_modulus"].Value.ToString().Trim()) * dnum2, 4);

                                    dvg_move_out.Rows[row_no].Cells["move_cubage"].Value = Math.Round((Convert.ToDouble(dvg_move_out.Rows[row_no].Cells["cubage"].Value.ToString().Trim()) / Convert.ToDouble(dvg_move_out.Rows[row_no].Cells["stock_qty_m"].Value.ToString().Trim())) * dnum2, 4); ;

                                    dvg_move_out.Rows[row_no].Cells["move_gross_weight"].Value = Math.Round((Convert.ToDouble(dvg_move_out.Rows[row_no].Cells["gross_weight"].Value.ToString().Trim()) / Convert.ToDouble(dvg_move_out.Rows[row_no].Cells["stock_qty_m"].Value.ToString().Trim())) * dnum2, 4); ;

                                    dvg_move_out.Rows[row_no].Cells["move_net_weight"].Value = Math.Round((Convert.ToDouble(dvg_move_out.Rows[row_no].Cells["net_weight"].Value.ToString().Trim()) / Convert.ToDouble(dvg_move_out.Rows[row_no].Cells["stock_qty_m"].Value.ToString().Trim())) * dnum2, 4); ;
                                    dvg_move_out.Rows[row_no].Cells["move_qty_m"].Value = dnum2;
                                }
                            }
                        }
                        catch (Exception)
                        {
                            dvg_move_out.Rows[e.RowIndex].ErrorText = "必须输入数字";
                            MessageBox.Show("请输入数字 ");
                            e.Cancel = true;
                        }
                    }
                }
            }
        }

        private void dvg_move_out2_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            int row_no;
            if (dvg_move_out2.CurrentRow != null)
            {
                row_no = e.RowIndex;
                if (row_no >= 0)
                {
                    if (dvg_move_out2.Columns[e.ColumnIndex].Name.ToString().Trim() == "move_qty_m2")
                    {
                        try
                        {
                            if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
                            {

                            }
                            else
                            {
                                double dnum = Convert.ToDouble(dvg_move_out2.Rows[e.RowIndex].Cells["stock_qty_m2"].Value.ToString().Trim());
                                double dnum2 = Convert.ToDouble(e.FormattedValue.ToString());
                                if (dnum2.ToString().Trim().Substring(0, 1) == "-")
                                {
                                    dvg_move_out2.Rows[e.RowIndex].ErrorText = "移库数不能为负数";
                                    MessageBox.Show("移库数不能为负数");
                                    e.Cancel = true;
                                }
                                if (dnum2 > dnum)
                                {
                                    dvg_move_out2.Rows[e.RowIndex].ErrorText = "移库数大于可用数量";
                                    MessageBox.Show("移库数大于可用数量");
                                    e.Cancel = true;
                                }
                                else //计算重量体积
                                {

                                    dvg_move_out2.Rows[row_no].Cells["move_qty_s2"].Value = Math.Round(Convert.ToDouble(dvg_move_out2.Rows[row_no].Cells["convert_modulus2"].Value.ToString().Trim()) * dnum2, 4);

                                    dvg_move_out2.Rows[row_no].Cells["move_cubage2"].Value = Math.Round((Convert.ToDouble(dvg_move_out2.Rows[row_no].Cells["cubage2"].Value.ToString().Trim()) / Convert.ToDouble(dvg_move_out2.Rows[row_no].Cells["stock_qty_m2"].Value.ToString().Trim())) * dnum2, 4); ;

                                    dvg_move_out2.Rows[row_no].Cells["move_gross_weight2"].Value = Math.Round((Convert.ToDouble(dvg_move_out2.Rows[row_no].Cells["gross_weight2"].Value.ToString().Trim()) / Convert.ToDouble(dvg_move_out2.Rows[row_no].Cells["stock_qty_m2"].Value.ToString().Trim())) * dnum2, 4); ;

                                    dvg_move_out2.Rows[row_no].Cells["move_net_weight2"].Value = Math.Round((Convert.ToDouble(dvg_move_out2.Rows[row_no].Cells["net_weight2"].Value.ToString().Trim()) / Convert.ToDouble(dvg_move_out2.Rows[row_no].Cells["stock_qty_m2"].Value.ToString().Trim())) * dnum2, 4); ;
                                    dvg_move_out2.Rows[row_no].Cells["move_qty_m2"].Value = dnum2;
                                }
                            }
                        }
                        catch (Exception)
                        {
                            dvg_move_out2.Rows[e.RowIndex].ErrorText = "必须输入数字";
                            MessageBox.Show("请输入数字 ");
                            e.Cancel = true;
                        }
                    }
                }
            }
        }

        private void dvg_move_out2_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dvg_move_out2.CurrentRow != null)
            {
                if (dvg_move_out2.Columns[e.ColumnIndex].Name.ToString().Trim() == "movein_location2")
                {
                    if (dvg_move_out2.Rows[e.RowIndex].Cells["movein_warehouse2"].Value.ToString().Trim() != "")
                    {
                        w_inv003locationlist fr = new w_inv003locationlist(dvg_move_out2.Rows[e.RowIndex].Cells["movein_warehouse2"].Value.ToString().Trim());
                        fr.ShowDialog();
                        dvg_move_out2.Rows[e.RowIndex].Cells["movein_location2"].Value = fr.str_location_code.Trim();
                    }
                }
            }
        }

        private void dvg_move_out2_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (g_str_loctype.Trim() == "1")
            {
                string str_name = "", str_location = "";
                if (dvg_move_out2.CurrentRow != null)  //说明选择了行号
                {
                    str_name = dvg_move_out2.Columns[dvg_move_out2.CurrentCell.ColumnIndex].Name.ToString().Trim();
                    if (str_name == "movein_location2") //说明更改了fact_location
                    {
                        str_location = dvg_move_out2.Rows[dvg_move_out2.CurrentRow.Index].Cells["movein_location2"].EditedFormattedValue.ToString().Trim().ToUpper();
                        if (str_location.Trim() != "")
                        {
                            string str_sql = "select location_code from " + main.g_space + ".mst_location where inv_org='" + main.g_org + "' and  location_code like '%" + str_location + "%' and main_dist<>'D'";
                            if (main.dbtype == "SQL")
                                str_location = main.dbservice.Sql_exec_selectstring(str_sql);
                            else
                                str_location = main.dbservice.oracle_exec_selectstring(str_sql);

                            dvg_move_out2.Rows[dvg_move_out2.CurrentRow.Index].Cells["movein_location2"].Value = str_location.ToUpper();
                        }
                    }
                }
            }
        }

        private void dvg_move_out_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (g_str_loctype.Trim() == "1")
            {
                string str_name = "", str_location = "";
                if (dvg_move_out.CurrentRow != null)  //说明选择了行号
                {
                    str_name = dvg_move_out.Columns[dvg_move_out.CurrentCell.ColumnIndex].Name.ToString().Trim();
                    if (str_name == "movein_location") //说明更改了fact_location
                    {
                        str_location = dvg_move_out.Rows[dvg_move_out.CurrentRow.Index].Cells["movein_location"].EditedFormattedValue.ToString().Trim().ToUpper();
                        if (str_location.Trim() != "")
                        {
                            string str_sql = "select location_code from " + main.g_space + ".mst_location where inv_org='" + main.g_org + "' and  location_code like '%" + str_location + "%' and main_dist<>'D'";
                            if (main.dbtype == "SQL")
                                str_location = main.dbservice.Sql_exec_selectstring(str_sql);
                            else
                                str_location = main.dbservice.oracle_exec_selectstring(str_sql);

                            dvg_move_out.Rows[dvg_move_out.CurrentRow.Index].Cells["movein_location"].Value = str_location.ToUpper();
                        }
                    }
                }
            }
        }

        private void w_inv003_Enter(object sender, EventArgs e)
        {
            btn_Query_Click(sender, new EventArgs());
        }


    }
}